<?xml version='1.0' encoding='iso-8859-1'?>
<!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
	<head>
		<title>
			pibrump.c
			</title>
		<meta http-equiv='content-type' content='text/html;iso-8859-1'/>
		<meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
		<meta name='author' content='cmaier@cmassoc.net'/>
		<meta name='robots' content='noindex,nofollow'/>
		<link href='toolkit.css' rel='stylesheet' type='text/css'/>
		</head>
	<body>
		<div class='headerlink'>
			[<a href='pibruin.c.html' title=' pibruin.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='pibscalers.c.html' title=' pibscalers.c '>NEXT</a>]
			</div>
<pre>
/*====================================================================*
 *
 *   Copyright (c) 2013 Qualcomm Atheros, Inc.
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or 
 *   without modification, are permitted (subject to the limitations 
 *   in the disclaimer below) provided that the following conditions 
 *   are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials 
 *     provided with the distribution.
 *
 *   * Neither the name of Qualcomm Atheros nor the names of 
 *     its contributors may be used to endorse or promote products 
 *     derived from this software without specific prior written 
 *     permission.
 *
 *   NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 
 *   GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE 
 *   COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR 
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 *   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 *
 *--------------------------------------------------------------------*/

/*====================================================================*
 *
 *   pibrump.c - Atheros Classification Rule Dump Utility;
 *
 *   This program read classification rules stored in a PIB file and
 *   prints them on stdout in a format similar to int6krule commands;
 *
 *
 *   Contributor(s):
 *      Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
 *
 *--------------------------------------------------------------------*/

/*====================================================================*&quot;
 *   system header files;
 *--------------------------------------------------------------------*/

#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdint.h&gt;
#include &lt;string.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;

/*====================================================================*
 *   custom header files;
 *--------------------------------------------------------------------*/

#include &quot;../tools/getoptv.h&quot;
#include &quot;../tools/memory.h&quot;
#include &quot;../tools/symbol.h&quot;
#include &quot;../tools/types.h&quot;
#include &quot;../tools/flags.h&quot;
#include &quot;../tools/files.h&quot;
#include &quot;../tools/error.h&quot;
#include &quot;../pib/pib.h&quot;
#include &quot;../plc/rules.h&quot;

/*====================================================================*
 *   custom source files;
 *--------------------------------------------------------------------*/

#ifndef MAKEFILE
#include &quot;../tools/getoptv.c&quot;
#include &quot;../tools/putoptv.c&quot;
#include &quot;../tools/version.c&quot;
#include &quot;../tools/lookup.c&quot;
#include &quot;../tools/reword.c&quot;
#include &quot;../tools/hexstring.c&quot;
#include &quot;../tools/hexdecode.c&quot;
#include &quot;../tools/fdchecksum32.c&quot;
#include &quot;../tools/memout.c&quot;
#include &quot;../tools/error.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../pib/pibfile1.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../plc/rules.c&quot;
#endif

/*====================================================================*
 *   program constants;
 *--------------------------------------------------------------------*/

#define PIB_MAX_AUTOCONN 16
#define PIB_MAX_PRIORITY_MAPS 8

#define PIB_AUTOCONN_COUNT_OFFSET 0x22C
#define PIB_PRIORITY_COUNT_OFFSET 0x228

#define PIB_AUTOCONN_OFFSET 0x310
#define PIB_PRIORITY_MAPS_OFFSET 0x230

/*====================================================================*
 *
 *   signed Classifier (struct PIBClassifier * classifier);
 *
 *   plc.h
 *
 *   This function for program pibrump displays a single classifier;
 *
 *   Contributor(s):
 *      Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
 *
 *--------------------------------------------------------------------*/

signed Classifier (struct PIBClassifier * classifier)

{
	char buffer [sizeof (classifier-&gt;CR_VALUE) * 3 + 1];
	uint32_t val32;
	uint16_t val16;
	uint8_t val8;
	printf (&quot;%s %s&quot;, reword (classifier-&gt;CR_PID, fields, SIZEOF (fields)), reword (classifier-&gt;CR_OPERAND, operators, SIZEOF (operators)));
	switch (classifier-&gt;CR_PID)
	{
	case FIELD_ETH_SA:
	case FIELD_ETH_DA:
		printf (&quot; %s&quot;, hexstring (buffer, sizeof (buffer), classifier-&gt;CR_VALUE, ETHER_ADDR_LEN));
		break;
	case FIELD_IPV4_SA:
	case FIELD_IPV4_DA:
		putchar (' ');
		memout (classifier-&gt;CR_VALUE, IPv4_LEN, &quot;%d&quot;, 1, '.', 0, stdout);
		break;
	case FIELD_IPV6_SA:
	case FIELD_IPV6_DA:
		putchar (' ');
		memout (classifier-&gt;CR_VALUE, IPv6_LEN, &quot;%02x&quot;, 2, ':', 0, stdout);
		break;
	case FIELD_VLAN_UP:
	case FIELD_IPV6_TC:
	case FIELD_IPV4_TOS:
	case FIELD_IPV4_PROT:
		memcpy (&amp;val8, classifier-&gt;CR_VALUE, sizeof (val8));
		printf (&quot; 0x%02X&quot;, val8);
		break;
	case FIELD_VLAN_ID:
	case FIELD_TCP_SP:
	case FIELD_TCP_DP:
	case FIELD_UDP_SP:
	case FIELD_UDP_DP:
	case FIELD_IP_SP:
	case FIELD_IP_DP:
		memcpy (&amp;val16, classifier-&gt;CR_VALUE, sizeof (val16));
		val16 = ntohs (val16);
		printf (&quot; %d&quot;, val16);
		break;
	case FIELD_ETH_TYPE:
		memcpy (&amp;val16, classifier-&gt;CR_VALUE, sizeof (val16));
		printf (&quot; 0x%04X&quot;, val16);
		break;
	case FIELD_IPV6_FL:
		memcpy (&amp;val32, &amp;classifier-&gt;CR_VALUE [0], sizeof (val32));
		val32 = ntohl (val32);
		printf (&quot; 0x%08X&quot;, val32);
		break;
	case FIELD_HPAV_MME:
		memcpy (&amp;val8, &amp;classifier-&gt;CR_VALUE [0], sizeof (val8));
		memcpy (&amp;val16, &amp;classifier-&gt;CR_VALUE [1], sizeof (val16));
		printf (&quot; %02x:%04x&quot;, val8, val16);
		break;
	case FIELD_TCP_ACK:
		{
			code_t val;
			memcpy (&amp;val, classifier-&gt;CR_VALUE, sizeof (val));
			printf (&quot; %s&quot;, reword (val, states, SIZEOF (states)));
		}
		break;
	case FIELD_VLAN_TAG:
		{
			code_t val;
			memcpy (&amp;val, classifier-&gt;CR_VALUE, sizeof (val));
			printf (&quot; %s&quot;, reword (val, states, SIZEOF (states)));
		}
		break;
	default:
		printf (&quot; *****UNSUPPORTED CODE*****&quot;);
		break;
	}
	return (0);
}

/*====================================================================*
 *
 *   signed AutoConnection (struct auto_connection * auto_connection, flag_t flags)
 *
 *   plc.h
 *
 *   This function for program pibrump displays a single AutoConnection
 *   structure;
 *
 *   Contributor(s):
 *      Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
 *
 *--------------------------------------------------------------------*/

signed AutoConnection (struct auto_connection * auto_connection)

{
	int i;
	if (auto_connection-&gt;MACTION == ACTION_TAGTX)
	{
		printf (&quot;-T 0x%08X -V %d &quot;, ntohl (auto_connection-&gt;cspec.VLAN_TAG), LE16TOH (auto_connection-&gt;cspec.CSPEC_VERSION));
	}
	printf (&quot;%s&quot;, reword (auto_connection-&gt;MACTION, actions, SIZEOF (actions)));
	printf (&quot; %s &quot;, reword (auto_connection-&gt;MOPERAND, operands, SIZEOF (operands)));
	for (i = 0; i &lt; LE16TOH (auto_connection-&gt;NUM_CLASSIFIERS); ++i)
	{
		Classifier (&amp;auto_connection-&gt;CLASSIFIER [i]);
		putchar (' ');
	}
	printf (&quot;add perm\n&quot;);
	return (0);
}

/*====================================================================*
 *
 *   signed ClassifierPriorityMap (struct classifier_priority_map * map)
 *
 *   plc.h
 *
 *   This function for program pibrump displays a single
 *   ClassifierPriorityMap structure;
 *
 *   Contributor(s):
 *      Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
 *
 *--------------------------------------------------------------------*/

signed ClassifierPriorityMap (struct classifier_priority_map * map)

{
	printf (&quot;%s Any &quot;, reword (LE32TOH (map-&gt;Priority), actions, SIZEOF (actions)));
	Classifier (&amp;map-&gt;CLASSIFIER);
	printf (&quot; add perm\n&quot;);
	return (0);
}

/*====================================================================*
 *
 *   int main (int argc, char const * argv[]);
 *
 *--------------------------------------------------------------------*/

int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		&quot;eqv&quot;,
		&quot;pibfile&quot;,
		&quot;Atheros Classification Rule Dump Utility&quot;,
		&quot;e\tredirect stderr messages to stdout&quot;,
		&quot;q\tquiet mode&quot;,
		&quot;v\tverbose mode&quot;,
		(char const *) (0)
	};
	struct auto_connection auto_connection [PIB_MAX_AUTOCONN];
	struct classifier_priority_map classifier_priority_map [PIB_MAX_PRIORITY_MAPS];
	uint32_t AutoConnection_count;
	uint32_t PriorityMaps_count;
	unsigned i;
	flag_t flags = (flag_t)(0);
	struct _file_ pib;
	signed c;
	optind = 1;
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch ((char) (c))
		{
		case 'e':
			dup2 (STDOUT_FILENO, STDERR_FILENO);
			break;
		case 'q':
			_setbits (flags, PIB_SILENCE);
			break;
		case 'v':
			_setbits (flags, PIB_VERBOSE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	while ((argc) &amp;&amp; (* argv))
	{
		pib.name = * argv;
		if ((pib.file = open (pib.name, O_BINARY|O_RDONLY)) == -1)
		{
			error (1, errno, &quot;%s&quot;, pib.name);
		}
		if (pibfile1 (&amp;pib))
		{
			error (1, errno, &quot;Bad PIB file: %s&quot;, pib.name);
		}
		if (lseek (pib.file, PIB_AUTOCONN_COUNT_OFFSET, SEEK_SET) != PIB_AUTOCONN_COUNT_OFFSET)
		{
			error (1, errno, &quot;could not seek to AutoConnection count&quot;);
		}
		if (read (pib.file, &amp;AutoConnection_count, sizeof (AutoConnection_count)) != sizeof (AutoConnection_count))
		{
			error (1, errno, &quot;could not read AutoConnection count&quot;);
		}
		if (lseek (pib.file, PIB_AUTOCONN_OFFSET, SEEK_SET) != PIB_AUTOCONN_OFFSET)
		{
			error (1, errno, &quot;could not seek to AutoConnections&quot;);
		}
		if (read (pib.file, &amp;auto_connection, sizeof (auto_connection)) != sizeof (auto_connection))
		{
			error (1, errno, &quot;could not read AutoConnections&quot;);
		}
		if (lseek (pib.file, PIB_PRIORITY_COUNT_OFFSET, SEEK_SET) != PIB_PRIORITY_COUNT_OFFSET)
		{
			error (1, errno, &quot;could not seek to PriorityMaps count&quot;);
		}
		if (read (pib.file, &amp;PriorityMaps_count, sizeof (PriorityMaps_count)) != sizeof (PriorityMaps_count))
		{
			error (1, errno, &quot;could not read PriorityMaps count&quot;);
		}
		if (lseek (pib.file, PIB_PRIORITY_MAPS_OFFSET, SEEK_SET) != PIB_PRIORITY_MAPS_OFFSET)
		{
			error (1, errno, &quot;could not seek to Priority Map&quot;);
		}
		if (read (pib.file, &amp;classifier_priority_map, sizeof (classifier_priority_map)) != sizeof (classifier_priority_map))
		{
			error (1, errno, &quot;could not read Priority Map&quot;);
		}
		close (pib.file);
		if (_allclr (flags, PIB_SILENCE))
		{
			printf (&quot;# auto connection rules:\n&quot;);
		}
		for (i = 0; i &lt; AutoConnection_count; ++i)
		{
			AutoConnection (&amp;auto_connection [i]);
		}
		if (_allclr (flags, PIB_SILENCE))
		{
			printf (&quot;# priority mapping rules:\n&quot;);
		}
		for (i = 0; i &lt; PriorityMaps_count; ++i)
		{
			ClassifierPriorityMap (&amp;classifier_priority_map [i]);
		}
		argv++;
		argc--;
	}
	exit (0);
}


</pre>
		<div class='footerlink'>
			[<a href='pibruin.c.html' title=' pibruin.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='pibscalers.c.html' title=' pibscalers.c '>NEXT</a>]
			</div>
		</body>
	</html>
